package models

import (
	"time"

	"gorm.io/gorm"
)

type Comment struct {
	ID        uint           `json:"id" gorm:"primaryKey"`
	Content   string         `json:"content" gorm:"type:text;not null"`
	ArticleID uint           `json:"article_id" gorm:"not null;index"` // 属于哪篇文章
	UserID    uint           `json:"user_id" gorm:"not null;index"`    // 由哪个用户发表
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
	// 关联关系
	Article Article `json:"-" gorm:"foreignKey:ArticleID;constraint:OnDelete:CASCADE;"`           // 为了预加载用户信息，这里不序列化文章
	User    User    `json:"user,omitempty" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;"` // 发表评论的用户信息
}
